#include <REGX52.H>
#include <intrins.h>

sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
sbit ENLED=P1^4;

/// @brief LED初始化函数
void LED_Init(){
	ADDR0=0;
	ADDR1=1;
	ADDR2=1;
	ADDR3=1;
	ENLED=0;
}

/// @brief LED序号数组
unsigned char LED_Num[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};

/// @brief 流水灯形式之一
void LED_WaterFall_1(){
	unsigned char i;
	unsigned int j;
	for ( i = 0; i < 8; i++)
	{
		P0=LED_Num[i];
		//延时
		for ( j = 0; j < 7000 ;j++);
	}
	for ( i = 7; i > 0; i--)
	{
		P0=LED_Num[i];
		//延时
		for ( j = 0; j < 7000 ;j++);
	}
}

/// @brief _crol_左移  _cror_右移
void LED_WaterFall_2(){
	unsigned char i;
	unsigned int j;
	for(i=0;i<8;i++)
	{
		P0=_crol_(0xFE,i);
		for ( j = 0; j < 7000 ;j++);
	}
	for(i=0;i<8;i++)
	{
		P0=_cror_(0x7F,i);
		for ( j = 0; j < 7000 ;j++);
	}
}

void main(){
	LED_Init();
	
	while(1){
		LED_WaterFall_1();
		LED_WaterFall_2();
	}
}